using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WbsEditor.Generation
{
    public partial class GenerateProgressDialog : Form
    {
        public GenerateProgressDialog()
        {
            InitializeComponent();

            Maximum = 100;
            Minimum = 0;
            ProgressValue = 0;

            _timer.Start();
        }

        public void OnTimerTick(object sender, EventArgs e)
        {
            if (_progressBar.Maximum != Maximum)
                _progressBar.Maximum = Maximum;
            if (_progressBar.Minimum != Minimum)
                _progressBar.Minimum = Minimum;
            if (_progressBar.Value != ProgressValue)
                _progressBar.Value = ProgressValue;
            if (_progressLabel.Text != ProgressText)
                _progressLabel.Text = ProgressText;
            if (RequestQuit)
            {
                Dispose();
            }
        }

        public void OnThreadFinished(object sender, EventArgs e)
        {
            RequestQuit = true;
        }

        private string _progressText = "Working...";
        public string ProgressText
        {
            get { return _progressText; }
            set { _progressText = value; }
        }

        private int _minimum;
        public int Minimum
        {
            get { return _minimum; }
            set { _minimum = value; }
        }

        private int _maximum;
        public int Maximum
        {
            get { return _maximum; }
            set { _maximum = value; }
        }

        private int _value;
        public int ProgressValue
        {
            get { return _value; }
            set { _value = value; }
        }

        private bool _requestQuit;
        public bool RequestQuit
        {
            get { return _requestQuit; }
            set { _requestQuit = value; }
        }

        public void Tick()
        {
            if (ProgressValue < Maximum)
                ProgressValue++;
        }
    }
}